<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/5/5 0005
 * Time: 下午 7:53
 */

namespace app\index\model\guo;
use think\Model;
use think\Db;

class DdUsersBalanceLog extends Model
{
    public function insert_log($data){

        if(Db::name("dd_users")->field("uid")->where("uid",$data["uid"])->find()){

            if($data["content"]=="签到"){
                $res =  Db::name("dd_users_balance")->where("uid",$data["uid"])->find();
                $point = $data["number"] + $res['point'];
                $sum_point = $data["number"] + $res['sum_point'];
                Db::name("dd_users_balance")
                    ->where("uid",$data["uid"])
                    ->update(["sign_time" => $data["create_time"],"point" =>$point, "sum_point" =>$sum_point]);
            }else{

            }
            if(Db::name("dd_users_balance_log")->insert($data)){
                return 1;
            }else{
                return 0;
            }

        }else{

            return -1;

        }

    }
}